﻿using Md.Api.Entity.DapperModels.MdDB;
using Md.Api.Model.Manage.MdBanner.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Manage.MdBanner;
/// <summary>
/// 添加轮播图服务
/// </summary>
public class InsertMdBannerService : ApiBase<RequestInsertMdBannerModel>
{
    /// <summary>
    /// 轮播图仓储
    /// </summary>
    public MdBannerRep mdBannerRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var model = new MdBannerModel();

        model.Title = Parameter.Title;
        model.Picture = Parameter.Picture;
        model.Url = Parameter.Url;
        model.Category = Parameter.Category;
        model.Sort = Parameter.Sort;
        model.Status = Parameter.Status;
        model.DelFlag = "0";
        model.CreateBy = userKey?.ToString();
        model.CreateTime = DateTime.Now;

        var res = mdBannerRep.Insert(model);

        if (res > 0)
        {
            Result.Data = mdBannerRep.GetMdBannerById(Convert.ToInt64(res));
        }
        else
        {
            Result.Data = res;
        }
    }
}

